package cn.hh.lambda;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @Author huangh
 * @date 2021/09/23
 * @Description:
 */
public class LambdaTest2 {

    @Test
    public void testClosure() throws InterruptedException {
        // 在匿名内部类的外面定义一个String变量
        final String str = "hello";
        // 构造一个匿名内部类对象
        Runnable r = () -> {
                System.out.println(str);
                System.out.println("this====>" + this);
        };

        new Thread(r).start();

        TimeUnit.SECONDS.sleep(1);
    }

}
